package com.frank.service.test3;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

import static com.frank.util.ByteBufferUtil.debugAll;

/**
 * @Author: huweifeng
 * @Date: 2024/12/11
 * @Description: 测试分散读取
 **/
public class TestScatteringReads {
    public static void main(String[] args) {
        // 读取字符串，结果为三个字符串
        try (FileChannel channel = new RandomAccessFile("words.txt", "r").getChannel()){
            ByteBuffer word1buffer = ByteBuffer.allocate(3);// 读取第一个单词
            ByteBuffer word2buffer = ByteBuffer.allocate(3);// 读取第二个单词
            ByteBuffer word3buffer = ByteBuffer.allocate(5);// 读取第三个单词
            word1buffer.flip();
            word2buffer.flip();
            word3buffer.flip();
            debugAll(word1buffer); // one todo：有点问题，打印出来的是...
            debugAll(word2buffer); // two
            debugAll(word3buffer); // three
        } catch (IOException e) {

        }
    }
}
